<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>209会议室申请管理</title>
    <link rel="shortcut icon" href="./fonts/favicon.png" />
    <link rel="stylesheet" href="./css/bootstrap.css">
    <link rel="stylesheet" href="./css/teacher_index.css">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
    <script src="./js/bootstrap.js"></script>
</head>
<body>
<div id="app">
    <nav class="navbar navbar-default navbar-static-top">
        <div class="container">
            <div class="navbar-header">

                <!-- Collapsed Hamburger -->
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
                    <span class="sr-only">Toggle Navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <!-- Branding Image -->
                <a class="navbar-brand" href="{{ url('/') }}">
                    {{ config('app.name', 'Laravel') }}
                </a>
            </div>

            <div class="collapse navbar-collapse" id="app-navbar-collapse">
                <!-- Left Side Of Navbar -->
                <ul class="nav navbar-nav">
                    &nbsp;
                </ul>

                <!-- Right Side Of Navbar -->
                <ul class="nav navbar-nav navbar-right">
                    <!-- Authentication Links -->
                    @if (Auth::guest())
                        <li><a href="{{ route('login') }}">登录</a></li>

                    @else
                        <li><a href="{{ url('teacher/index') }}">最新申请</a></li>
                        <li><a href="{{ url('teacher/history')}}">历史记录</a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                                {{ Auth::user()->name }} <span class="caret"></span>
                            </a>

                            <ul class="dropdown-menu" role="menu">
                                <li>
                                    <a href="{{ route('logout') }}"
                                       onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                        注销
                                    </a>

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                                        {{ csrf_field() }}
                                    </form>
                                </li>
                            </ul>
                        </li>
                    @endif
                </ul>
            </div>
        </div>
    </nav>

    @yield('content')
</div>
<div class="title">209会议室申请管理</div>

<!--<div class="title">209会议室申请管理</div>-->
<div class="topnav">
    <a href="#" style="font-size:1.6rem;margin-left:10px;line-height: 3rem;" data-toggle="modal" data-target="#tipModal">钥匙管理</a >
    <ul>
        <li><a href="{{url('teacher/index')}}">最新申请</a></li>
        <li ><a href="{{url('teacher/history')}}" class="unactive" >历史记录</a></li>
    </ul>
</div>
<div class="content">

    @if(!$recent->count())
    <div class="noapply"><p>暂无最新申请信息...</p></div>

    @else

        <div class="noapply"><p>有最新的申请消息</p></div>

    @foreach($recent as $apply)

    <div class="apply">

        <div class="imgBox">
            <img src="{{$apply->file}}" alt="申请图片" class="applyPic">
        </div>
        <div class="btnBox">
            <button class="btn btn-info" id="resolve" value="{{$apply->id}}">通过审核</button>
            <button class="btn btn-danger" id="reject" value="{{$apply->id}}" >拒绝审批</button>
        </div>
        <div class="infoBox">
            <div id='apply_id' class="hidden">
                {{$apply->id}}
            </div>
            <div>
                <p><span>会议主题:</span>{{$apply->meeting_subject}} </p>
            </div>
            <div>
                <p><span>申请人:</span>{{$apply->applyer_name}}</p>
                <p><span>学号:</span>{{$apply->stu_id}} </p>
            </div>
            <div>
                <p><span>电话号码:</span>{{$apply->phone}}&nbsp;&nbsp;</p>
                <p><span>邮箱:</span>{{$apply->email}}&nbsp;&nbsp;&nbsp;</p>
                <p><span>审核部门:</span>{{$apply->department}}</p>
            </div>
            <div>

                <p><span>申请时间:</span>{{$apply->apply_time}} {{$apply->day}} {{join_time($apply->exact_time)}}</p>
            </div>
        </div>
    </div>
    @endforeach
@endif

    <!--弹图 modal-->
    <div id="ShowImage_Form" class="modal">
        <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button">×</button>
        </div>
        <div class="modal-body imgShow" >
            <img src="" id="picPlus">
        </div>
    </div>
</div>

<!-- 钥匙管理模态框（Modal） -->
<div class="modal fade" id="tipModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" >
                    设置钥匙管理员
                </h4>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <span class="input-group-addon" >&nbsp;&nbsp;&nbsp;&nbsp;姓名&nbsp;&nbsp;&nbsp;&nbsp;</span>
                    <input type="text" class="form-control" placeholder="请输入管理员姓名" aria-describedby="sizing-addon2" id="key_user_name" value="{{ $key_user->name or '' }}">
                </div>
                <br>
                <div class="input-group">
                    <span class="input-group-addon" >电话号码&nbsp;</span>
                    <input type="text" class="form-control" placeholder="请输入管理员电话号码" aria-describedby="sizing-addon2" id="key_user_mobile"  value="{{ $key_user->phone or '' }}" >
                </div>
                <br>
                <div class="input-group">
                    <span class="input-group-addon" >邮箱地址&nbsp;</span>
                    <input type="text" class="form-control" placeholder="请输入管理员邮箱地址" aria-describedby="sizing-addon2" id="key_user_email"  value="{{ $key_user->email or '' }}">
                </div>
                <br>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" id="submit" >保存</button>
            </div>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal -->
</body>
</html>

<script>
    $(function(){

        //图片放大
        $(".applyPic").click(function(){
            var psrc=$(this).attr("src");
            $("#picPlus").attr("src",psrc)
            $("#ShowImage_Form").modal();
        })

        //通过
        $("#resolve").click(function(){
            var id=$(this).val()
            $.ajax({
                type: "GET",
                url: "{{url('pass_apply')}}",
                data:{
                    'id':id
                },
                success: function (response) {
                    if(response.code==200){
                        alert("申请通过成功")
                        window.location.reload()
                    }
                }
            });
        })


        //不通过
        $("#reject").click(function(){
            var id=$(this).val()
            $.ajax({
                type: "GET",
                url: "{{url('deny_apply')}}",
                data:{
                    'id':id
                },
                success: function (response) {
                    if(response.code==200){
                        alert("申请拒绝成功")
                        window.location.reload()
                    }
                }
            });
        })

        //管理员设置 保存按钮
        $("#submit").click(function(){
            var emailreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            var name =$("#key_user_name").val().replace(/\s*/g,"");
            var mobile=$("#key_user_mobile").val().replace(/\s*/g,"");
            var email=$("#key_user_email").val().replace(/\s*/g,"");
            if(name==''||mobile==''||email=='')
                alert("填写不能为空！")
            else if(mobile.length!=11)
                alert("手机号码不符合规范！")
            else if(!emailreg.test(email))
                alert("邮箱格式错误！")
            else{
                $.ajax({
                    type: "post",
                    url: "{{url("teacher/set_key_user")}}",
                    data: {
                        'email' : email,
                        'name'  : name,
                        'phone' : mobile,
                    },
                    success: function (response) {
                        if(response.code==200){
                            alert(response.message)
                            $("#tipModal").modal('hide')
                        }else{
                            alert(response.message)
                        }
                    }
                });
            }
        })

    })


</script>